package com.application.chiettinhdienluc.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.application.chiettinhdienluc.R;
import com.application.chiettinhdienluc.model.TramModel;

public class DanhMucTramAdapter extends BaseAdapter {
	public ArrayList<TramModel> itemList;
	Animation animation = null;

	public ArrayList<TramModel> getItemList() {
		return itemList;
	}

	private Activity ac;

	public DanhMucTramAdapter(Activity context, ArrayList<TramModel> countryList) {
		this.itemList = new ArrayList<TramModel>(countryList);
		ac = context;
	}

	private class ViewHolder {
		TextView tvSttValue;
		TextView tvMaTramValue;
		TextView tvTenTramValue;
		TextView tvCongsuatValue;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final ViewHolder holder;
		// View view = null;
		if (convertView == null) {
			holder = new ViewHolder();
			LayoutInflater inflater = LayoutInflater.from(ac);
			convertView = inflater.inflate(R.layout.danh_muc_tram_item, null);
			holder.tvSttValue = (TextView) convertView.findViewById(R.id.tvSttValue);
			holder.tvMaTramValue = (TextView) convertView.findViewById(R.id.tvMaTramValue);
			holder.tvTenTramValue = (TextView) convertView.findViewById(R.id.tvTenTramValue);
			holder.tvCongsuatValue = (TextView) convertView.findViewById(R.id.tvCongsuatValue);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		try {

			TramModel tram = itemList.get(position);
			holder.tvSttValue.setText(position + 1 + ".");
			holder.tvMaTramValue.setText(tram.getMaTram());
			holder.tvTenTramValue.setText(tram.getTenTram());
			holder.tvCongsuatValue.setText(tram.getCongSuatTram() + "");
			animation = AnimationUtils.loadAnimation(ac, R.anim.push_up_in);
			convertView.startAnimation(animation);
			animation = null;

		} catch (Exception e) {
			e.printStackTrace();
		}
		return convertView;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return itemList.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return itemList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	public void setItemList(ArrayList<TramModel> countryList) {
		this.itemList = new ArrayList<TramModel>(countryList);
	}

}
